package org.example.pdf;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.StandardDecryptionMaterial;

import java.io.File;

public class RemovePwd {

    /**
     * 去处掉 pdf 的 编辑密码
     *
     * @param args
     */
    public static void main(String[] args) {
        // 指定PDF文件的路径
        String pdfPath = "file/teacher.pdf";

        try (PDDocument document = PDDocument.load(new File(pdfPath) )) {
            // 移除PDF密码
            document.setAllSecurityToBeRemoved(true);

            // 指定输出文件的路径
            String outputPdfPath = "file/teacher_no_pwd.pdf";
            // 将解密后的文件保存为新的PDF
            document.save(new File(outputPdfPath));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
